<template>
  <div>
    <BasicTable @register="registerTable" @fetch-success="onFetchSuccess" ref="tableRef">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '审批进度',
              onClick: handleDetail.bind(null, record),
              ifShow: !teamGroupsSelete,
            },
          ]"
        />
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent, reactive, toRefs, unref, ref } from 'vue';

  import { BasicTable, useTable, TableAction, TableActionType } from '/@/components/Table';
  import { getTodoList } from '/@/api/backs/workFlow/process';

  import { columns, searchFormSchema } from './components/tableData';
  import { useGo } from '/@/hooks/web/usePage';
  export default defineComponent({
    name: 'MenuManagement',
    components: { BasicTable, TableAction },
    props: {
      teamGroupsSelete: {
        type: Boolean,
        default: false,
      },
    },
    setup(props) {
      const tableRef = ref<Nullable<TableActionType>>(null);
      const [registerTable, { reload, getSelectRows, setSelectedRowKeys }] = useTable({
        title: '待办列表',
        api: getTodoList,
        columns,
        formConfig: {
          labelWidth: 100,
          schemas: searchFormSchema,
        },
        useSearchForm: !props.teamGroupsSelete,
        showTableSetting: !props.teamGroupsSelete,
        rowSelection: props.teamGroupsSelete,
        beforeFetch: (res) => {
          if (res.createTime && res.createTime.length) {
            res.startTime = res.createTime[0];
            res.endTime = res.createTime[1];
            delete res.createTime;
          }
        },
        actionColumn: {
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      const data: any = reactive({
        type: 'add',
      });
      const go = useGo();

      const handleDetail = (record: Recordable) => {
        go('/workFlowManage/task/detail/' + record.processInstance.id);
      };
      const onFetchSuccess = () => {};
      return {
        ...toRefs(data),
        tableRef,
        registerTable,
        handleDetail,
        onFetchSuccess,
      };
    },
  });
</script>
